package com.activemanager.gearCenter;

import java.io.InputStream;

import com.activemanager.dashboard.H0Activity;
import com.activemanager.dashboard.H2Activity;
import com.activemanager.myHealthProfile.Q1MainActivity;
import com.example.android.navigationdrawerexample.R;
import com.example.android.navigationdrawerexample.R.drawable;
import com.example.android.navigationdrawerexample.R.id;
import com.example.android.navigationdrawerexample.R.layout;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.ToggleButton;

public class GearCenter  extends Activity {
	
	int mChecked = 0;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gearcenter_g1);
		initPic();
		
		RelativeLayout relativLayout1 = (RelativeLayout) findViewById(R.id.relativLayout1);
		RelativeLayout relativLayout2 = (RelativeLayout) findViewById(R.id.relativLayout2);
		RelativeLayout relativLayout3 = (RelativeLayout) findViewById(R.id.relativLayout3);
		RelativeLayout relativLayout5 = (RelativeLayout) findViewById(R.id.relativLayout5);
		final Intent intent = new Intent();
		
		final BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
		
		relativLayout1.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				if(mChecked==0){
					final Dialog dialog = new Dialog(GearCenter.this,
							R.style.MyDialog);
					
					dialog.setContentView(R.layout.p18);
					
					final ImageView img = (ImageView) dialog.findViewById(R.id.imageView1);
					final TextView tv = (TextView) dialog.findViewById(R.id.textView2);
					InputStream is = getResources().openRawResource(
							R.drawable.g61_normal);
					Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
					img.setBackgroundDrawable(new BitmapDrawable(bit));
					tv.setText("Active Shoes");
					createDialog(dialog);
					
					Button ok = (Button) dialog.findViewById(R.id.btn_ok);
					ok.setOnClickListener(new OnClickListener(){

						@Override
						public void onClick(View arg0) {
							// TODO Auto-generated method stub
							dialog.dismiss();
						}
						
					});
				}
				if(mChecked==1){
					intent.setClass(GearCenter.this, G2Pressure.class);
					startActivity(intent);
				}
			}
		});
		relativLayout2.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				final Dialog dialog = new Dialog(GearCenter.this,
						R.style.MyDialog);
				
				dialog.setContentView(R.layout.p18);
				
				final ImageView img = (ImageView) dialog.findViewById(R.id.imageView1);
				final TextView tv = (TextView) dialog.findViewById(R.id.textView2);
				InputStream is = getResources().openRawResource(
						R.drawable.g53_normal);
				Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
				img.setBackgroundDrawable(new BitmapDrawable(bit));
				tv.setText("Skin Shoes");
				createDialog(dialog);
				
				Button ok = (Button) dialog.findViewById(R.id.btn_ok);
				ok.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
					
				});
			}

		});
		
		
		relativLayout3.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				final Dialog dialog = new Dialog(GearCenter.this,
						R.style.MyDialog);
				
				dialog.setContentView(R.layout.p18);
				
				final ImageView img = (ImageView) dialog.findViewById(R.id.imageView1);
				final TextView tv = (TextView) dialog.findViewById(R.id.textView2);
				InputStream is = getResources().openRawResource(
						R.drawable.g45_normal);
				Bitmap bit = BitmapFactory.decodeStream(is, null, opt);
				img.setBackgroundDrawable(new BitmapDrawable(bit));
				createDialog(dialog);
				
				tv.setText("Active Wristlet");
				Button ok = (Button) dialog.findViewById(R.id.btn_ok);
				ok.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
					
				});
				
			}

		});
		
		
//		textView1.setOnClickListener(new OnClickListener(){
//
//			@Override
//			public void onClick(View arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//			
//		});
		
		final ToggleButton toggleButton1 = (ToggleButton) findViewById(R.id.toggleButton1);
		final ToggleButton toggleButton2 = (ToggleButton) findViewById(R.id.toggleButton2);
		toggleButton1.setOnCheckedChangeListener(new OnCheckedChangeListener(){

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
				// TODO Auto-generated method stub
				if(isChecked){
					mChecked =1	;
					toggleButton2.setChecked(false);
				}else mChecked=0;
			}
			
		});
		
		toggleButton2.setOnCheckedChangeListener(new OnCheckedChangeListener(){

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
				// TODO Auto-generated method stub
				if(isChecked){
					mChecked=0;
					toggleButton1.setChecked(false);
				}
			}
			
		});
		
		ImageView img_home = (ImageView) findViewById(R.id.imageView);
		img_home.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}});

	}
	
	private void createDialog(Dialog dialog) {
		// TODO Auto-generated method stub
		dialog.show();
		Window dialogWindow = dialog.getWindow();
		WindowManager m = getWindowManager();
		Display d = m.getDefaultDisplay();
		WindowManager.LayoutParams p = dialogWindow.getAttributes();
		p.height = (int) (d.getHeight() * 0.8);
		p.width = (int) (d.getWidth() * 0.9);
		dialogWindow.setAttributes(p);
		
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
		RelativeLayout bgLayout = (RelativeLayout) dialog.findViewById(R.id.dLinearLayout);
//		InputStream is = getResources().openRawResource(
//				R.drawable.u165_normal);
//		Bitmap bgbit = BitmapFactory.decodeStream(is, null, opt);
//		bgLayout.setBackgroundDrawable(new BitmapDrawable(bgbit));
		bgLayout.setBackgroundResource(R.drawable.bg_for_popup_54);
		
		
	}

	private void initPic() {
		// TODO Auto-generated method stub
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
		LinearLayout bgLayout = (LinearLayout) findViewById(R.id.linearLayout1);
//		InputStream is = getResources().openRawResource(
//				R.drawable.background_normal);
//		Bitmap bgbit = BitmapFactory.decodeStream(is, null, opt);
//		bgLayout.setBackgroundDrawable(new BitmapDrawable(bgbit));
		bgLayout.setBackgroundResource(R.drawable.bg_540);
	}
}
